import { Vec3, Node, Vec2 } from 'cc';
// 碰撞掩码值
export const ColliderMask = {
  DEFAULT: 1 << 0, // 默认
  BALL: 1 << 1,    // 普通球
  MAINBALL: 1 << 2, // 主球
  DESKTOP: 1 << 3, // 桌面
  DESKEDGE: 1 << 4, // 桌边
  DESKHOLE: 1 << 5, // 桌球洞
}

export enum CameraMoveType {
  /** 相机紧跟随目标移动 */
  Default = 0,  // 2D视图下的默认相机位
  Default3DView = 1, // 3D 视图
  FollowTarget = 2, // 跟随物体
  SmoothMoveTo = 3, // 平滑移动
  AimPointDirection = 4, // 瞄准物体
  FixedPointTarget = 5, // 固定点
  StartGameScene = 100, // 开始游戏的场景
}

export enum WatchViewType {
  View3D = 0,  // 3D视图
  View2D = 1,  // 2D平面视图
}

// 自动适配屏幕的位置
export function autoFitScreen(node: Node) {
  const scalew = screen.width / 1280;
  const scaleh = screen.height / 720;
  node.setPosition(new Vec3(scalew * node.position.x, scaleh * node.position.y, 0));
}

// 产生随机数函数
export function randomGenRoomId() {
  var rnd = "2";
  for (var i = 0; i < 10; i++) {
    rnd += (Math.floor(Math.random() * 10)).toString();
  }
  return rnd;
}

// 随机生成游戏ID
export function randomGenGameId() {
  var rnd = "222";
  for (var i = 0; i < 15; i++) {
    rnd += Math.floor(Math.random() * 10).toString();
  }
  return rnd;
}

// 随机生成用户ID
export function randomGenUserId() {
  var rnd = "2222";
  for (var i = 0; i < 8; i++) {
    rnd += Math.floor(Math.random() * 10).toString();
  }
  return rnd;
}

// 计算距离
export function distanceLength(pa: Vec3, pb: Vec3) {
  return Math.sqrt((pa.x - pb.x) * (pa.x - pb.x) + (pa.y - pb.y) * (pa.y - pb.y) + (pa.z - pb.z) * (pa.z - pb.z));
}

export function distanceLengthV2(pa: Vec2, pb: Vec2) {
  return Math.sqrt((pa.x - pb.x) * (pa.x - pb.x) + (pa.y - pb.y) * (pa.y - pb.y));
}